/* GUI CONVERTED from reset.p (converter v1.76) Sun Aug 25 20:59:55 2002 */
/* reset.p - REPETITIVE SETUP LABOR TRANSACTION                               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5.3.5 $                                                               */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/29/95   BY: dzn *F0PN*                */
/* REVISION: 7.3      LAST MODIFIED: 02/21/96   BY: jym *G1M9*                */
/* REVISION: 7.3      LAST MODIFIED: 05/16/96   BY: *G1VW* Julie Milligan     */
/* REVISION: 7.3      LAST MODIFIED: 07/02/96   BY: *G1Z7* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: *K001* Alma Lara          */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* Revision: 1.5.3.4    BY: Robin McCarthy       DATE: 10/01/01  ECO: *P025*  */
/* $Revision: 1.5.3.5 $         BY: Vivek Gogte          DATE: 08/06/02  ECO: *N1QQ*  */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*V8:ConvertMode=Maintenance                                                  */

{mfdtitle.i "2+ "}

{gldydef.i new}
{gldynrm.i new}

define buffer next_wr_route for wr_route.
define buffer ptmstr for pt_mstr.
define variable batchqty as decimal.
define variable comp as character.
define variable cumwo_lot as character.
define variable rejected like mfc_logical.
define variable elapse as decimal format ">>>>>>>>.999".
define variable schedwo_lot as character.
define variable undo_stat like mfc_logical no-undo.
define variable trans_type as character.
define variable ophist_recid as recid.
define variable yn like mfc_logical.
define variable i as integer.
define variable j as integer.
define variable date_change as integer.

{retrform.i new}

define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

eff_date = today.
find first gl_ctrl no-lock.

{gprun.i ""redflt.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   /*GET EMP, EFFDATE, SHIFT, SITE, CONTROLTOTAL FROM USER*/
   {gprun.i ""retrin1.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if undo_stat then undo, leave.

   wo-loop:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      /*GET ITEM, OP, LINE FROM USER*/
      {gprun.i ""retrin2.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if undo_stat then undo, leave.

      /*FIND REPETITIVE SCHEDULE TO UPDATE*/
      {gprun.i ""reoptr1b.p""
         "(input site, input line, input part, input op, input eff_date,
           output routing, output bom_code, output schedwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if schedwo_lot = "?" then do:
         /* Unexploded schedule with consumption period */
         {pxmsg.i &MSGNUM=325 &ERRORLEVEL=3}
         next-prompt part.
         undo, retry.
      end.

      /*GET BOM, ROUTING FROM USER*/
      {gprun.i ""retrin3.p"" "(output undo_stat)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if undo_stat then undo, leave.

      /*FIND CUM ORDER.  */
      {gprun.i ""regetwo.p"" "(input site, input part, input eff_date,
           input line, input routing, input bom_code, output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /*VALIDATE THE OPERATION */
      {reopval.i &part = part
         &routing = routing
         &op = op
         &date = eff_date
         &prompt = op
         &frame = "a"
         &leave = ""no""
         &loop = "mainloop"
         }

      /* CREATE IT IF IT DOESN'T EXIST*/
      if cumwo_lot = ? then do:
         {gprun.i ""recrtwo.p"" "(input site, input part,
              input eff_date,
              input line, input routing, input bom_code, output cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if cumwo_lot = ? then next wo-loop.
         display cumwo_lot @ wo_lot with frame a.
      end.
      else do:
         display cumwo_lot @ wo_lot with frame a.
         find wo_mstr where wo_lot = cumwo_lot no-lock.

         if wo_status = "c" then do:
            /* CUM ORDER IS CLOSED */
            {pxmsg.i &MSGNUM=5101 &ERRORLEVEL=3}
            undo, retry.
         end.
      end.

      find wr_route where wr_lot = cumwo_lot and wr_op = op no-lock
         no-error.
      if not available wr_route then do:
         /* OPERATION DOES NOT EXIST */
         {pxmsg.i &MSGNUM=106 &ERRORLEVEL=3}
         next-prompt op with frame a.
         undo, retry.
      end.

      if not wr_milestone then do:
         /* OPERATION NOT A MILESTONE */
         {pxmsg.i &MSGNUM=560 &ERRORLEVEL=2}
      end.

      display wr_desc with frame a.

      assign
         wkctr = ""
         mch = ""
         dept = ""
         act_setup_hrs = 0
         start_run = ""
         earn_code = ""
         stop_run = ""
         .

      {gprun.i ""resetmno.p""
         "(input cumwo_lot, input op, output move_next_op)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      wkctr = wr_wkctr.
      mch = wr_mch.
      find wc_mstr where wc_wkctr = wkctr and wc_mch = mch no-lock.

      dept = wc_dept.
      find dpt_mstr where dpt_dept = wc_dept no-lock no-error.

      find wo_mstr where wo_lot = cumwo_lot no-lock.
      find pt_mstr where pt_part = wo_part no-lock.
      um = pt_um.

      find first ea_mstr where ea_type = "1" no-lock no-error.
      if available ea_mstr then earn_code = ea_earn.

      display
         wkctr
         mch
         wc_desc
         dept
         dpt_desc                when (available dpt_mstr)
         ""                 when (not available dpt_mstr) @ dpt_desc
         act_setup_hrs
         start_run
         earn_code
         ea_desc when (available ea_mstr)
         "" when (not available ea_mstr) @ ea_desc
         stop_run
      with frame set1.
      .

      do with frame set1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         for each sr_wkfl where sr_userid = mfguser exclusive-lock:
            delete sr_wkfl.
         end.

         for each pk_det where pk_user = mfguser exclusive-lock:
            delete pk_det.
         end.

         do with frame set1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            {regetwcm.i &framename=set1}

            if is_wiplottrace_enabled()
            then do:
               run init_labor_vars in h_wiplottrace_procs.
            end.

            do with frame set1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

               set
                  dept
                  act_setup_hrs
                  earn_code
                  editing:
                  if frame-field = "dept" then do:
                     {mfnp05.i dpt_mstr dpt_dept yes dpt_dept
                        "input frame set1 dept"}

                     if recno <> ? then
                     display dpt_dept @ dept
                        dpt_desc.
                  end.
                  else if frame-field = "earn_code" then do:
                     {mfnp05.i ea_mstr ea_earn yes ea_earn
                        "input frame set1
                          earn_code"}

                     if recno <> ? then
                           display ea_earn @ earn_code ea_desc.
                  end.
                  else do:
                     ststatus = stline[3].
                     status input ststatus.
                     readkey.
                     apply lastkey.
                  end.
               end.

               find dpt_mstr where dpt_dept = dept no-lock no-error.

               if not available dpt_mstr then do:
                  next-prompt dept.
                  /* DEPARTMENT DOES NOT EXIST */
                  {pxmsg.i &MSGNUM=532 &ERRORLEVEL=3}
                  undo, retry.
               end.

               display dpt_desc.

               if earn_code > "" then do:
                  find ea_mstr where ea_earn = earn_code no-lock
                     no-error.

                  if not available ea_mstr then do:
                     /* INVALID EARNINGS CODE */
                     {pxmsg.i &MSGNUM=4025 &ERRORLEVEL=3}
                     next-prompt earn_code.
                     undo, retry.
                  end.

                  display ea_desc.
               end.
               else display " " @ ea_desc.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.


            display start_run stop_run.

            if act_setup_hrs = 0 then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

               set start_run stop_run.

               if start_run > "" and stop_run = "" then do:
                  /* ELAPSED OR STOP TIME REQUIRED */
                  {pxmsg.i &MSGNUM=5102 &ERRORLEVEL=3}
                  undo, retry.
               end.

               {mfctime.i start_run stop_run}
               act_setup_hrs = elapse.
               display act_setup_hrs.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.

         end.
/*GUI*/ if global-beam-me-up then undo, leave.


         if is_wiplottrace_enabled()
            and is_operation_queue_lot_controlled(cumwo_lot, op, OUTPUT_QUEUE)
         then do:
            run get_labor_wip_lots_from_user in h_wiplottrace_procs
               (input part, input op).
         end.

         yn = yes.
         /* PLEASE CONFIRM UPDATE */
         {pxmsg.i &MSGNUM=32 &ERRORLEVEL=1 &CONFIRM=yn}
         if yn <> yes then undo, retry.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /****************************************************************/
      /*GOT ALL DATA AND VALIDATED IT, NOW WE CAN DO SOMETHING WITH IT*/
      /****************************************************************/

      /*NO TRANSACTION SHOULD BE PENDING HERE*/
      {gprun.i ""gpistran.p"" "(input 1, input """")"}
/*GUI*/ if global-beam-me-up then undo, leave.


      trans_type = "SETUP".

      {gprun.i ""reophist.p"" "(input trans_type,
           input cumwo_lot, input op, input emp,
           input wkctr, input mch, input dept, input shift,
           input eff_date,
           output ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /*LABOR AND BURDEN TRANSACTIONS*/
      {gprun.i ""relbra.p"" "(input cumwo_lot, input op,
           input wkctr, input mch, input dept, input act_setup_hrs,
           input eff_date,
           input earn_code, input emp, input false, input ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      for first op_hist where recid(op_hist) = ophist_recid no-lock:
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if is_wiplottrace_enabled()
         and is_operation_queue_lot_controlled(cumwo_lot, op,
         OUTPUT_QUEUE)
      then do:
         run labor_create_trace_records in h_wiplottrace_procs
            (input op_trnbr, input op_wo_lot, input op_wo_op).
      end.

      global_addr = string(ophist_recid).
      {gprun.i ""reintchk.p"" "(input cumwo_lot)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.

end.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.
